<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:medistat="http://java.sun.com/jsf/composite/medistat">
<h:head>
	
	<h:outputStylesheet library="css" name="weekTable.css" />
</h:head>

<h:body>
	<ui:composition template="/template/common/commonLayout.xhtml">

		<ui:define name="content">
			<h1 style="color: #709FB3;">#{translatorService.translate('loadSchedule.header')}</h1>
			<h:form id="dataTableForm">
				<p:messages id="messages"/>
				<h:panelGrid columns="2">
					<h:outputText value="Datum od:" />
					<p:calendar id="dateFrom" 
						value="#{loadScheduleController.dateFrom}"
						pattern="dd.MM.yyyy"
						effect="explode"
						onSelectUpdate="dateFrom dateUntil"
						selectListener="#{loadScheduleController.handleDateSelect}"
						/>
					
					<h:outputText value="Datum do:" />
					<p:calendar id="dateUntil" 
						value="#{loadScheduleController.dateUntil}" 
						pattern="dd.MM.yyyy"
						disabled="true"/>
				</h:panelGrid>
				<h:panelGrid columns="4">
					<p:commandButton value="#{translatorService.translate('loadSchedule.button.load')}"
						actionListener="#{loadScheduleController.loadSchedule()}"
						update="dataTableForm"/>
					<p:commandButton value="#{translatorService.translate('loadSchedule.button.clear')}" 
						actionListener="#{loadScheduleController.clearSchedule()}"
						update="dataTableForm"
						/>
					<p:commandButton value="#{translatorService.translate('loadSchedule.button.exportToExcel')}"
						actionListener="#{loadScheduleController.exportWithPoi()}" 
						rendered="#{loadScheduleController.schedules!=null and !loadScheduleController.schedules.isEmpty()}"						
						ajax="false"/>
						
				</h:panelGrid>
				<h:panelGrid rendered="#{loadScheduleController.schedules!=null and !loadScheduleController.schedules.isEmpty()}">
					<p:tabView switchType="ajax">
						<p:tab title="#{translatorService.translate('loadSchedule.tab.week1')}" rendered="#{loadScheduleController.schedules.size()>0}">
							<div style="overflow: auto">
							<medistat:weekTable 
								id="firstWeek" 
								schedule="#{loadScheduleController.schedules[0]}"
								controller="#{loadScheduleController}" />
							</div>
						</p:tab>
						<p:tab title="#{translatorService.translate('loadSchedule.tab.week2')}" rendered="#{loadScheduleController.schedules.size()>1}">
							<medistat:weekTable 
								id="secondWeek"
								schedule="#{loadScheduleController.schedules[1]}" 
								controller="#{loadScheduleController}" />
						</p:tab>
						<p:tab title="#{translatorService.translate('loadSchedule.tab.week3')}" rendered="#{loadScheduleController.schedules.size()>2}">
							<medistat:weekTable 
								id="thirdWeek" 
								schedule="#{loadScheduleController.schedules[2]}" 
								controller="#{loadScheduleController}"/>
						</p:tab>
						<p:tab title="#{translatorService.translate('loadSchedule.tab.week4')}" rendered="#{loadScheduleController.schedules.size()>3}">
							<medistat:weekTable 
								id="fourthWeek" 
								schedule="#{loadScheduleController.schedules[3]}" 
								controller="#{loadScheduleController}"/>
						</p:tab>
						<p:tab title="#{translatorService.translate('loadSchedule.tab.week5')}" rendered="#{loadScheduleController.schedules.size()>4}">
							<medistat:weekTable 
								id="fifthWeek"
								schedule="#{loadScheduleController.schedules[4]}" 
								controller="#{loadScheduleController}"/>
						</p:tab>
						<p:tab title="#{translatorService.translate('loadSchedule.tab.week6')}" rendered="#{loadScheduleController.schedules.size()>5}">
							<medistat:weekTable 
								id="sixthWeek"
								schedule="#{loadScheduleController.schedules[5]}" 
								controller="#{loadScheduleController}"/>
						</p:tab>
					</p:tabView>
				</h:panelGrid>
				<p:spacer width="100%" height="20" />
				<h:panelGrid rendered="#{loadScheduleController.freeDays!=null and !loadScheduleController.freeDays.isEmpty()}">
					<p:dataTable id="outOfWorkDatatable"
						value="#{loadScheduleController.freeDays}" var="freeDay"
						paginator="true"
						rows="10"
						>
						<p:column sortBy="#{loadScheduleController.getDiscreteValueProvider().getDiscreteValue('Doctors', freeDay.person.id)}">
							<f:facet name="header">
								<h:outputLabel value="#{translatorService.translate('outOfWork.doctor')}" />
							</f:facet>
							<h:outputText value="#{loadScheduleController.getDiscreteValueProvider().getDiscreteValue('Doctors', freeDay.person.id)}" />
						</p:column>
						<p:column sortBy="#{freeDay.outOfWork}">
							<f:facet name="header">
								<h:outputLabel value="#{translatorService.translate('outOfWork.typeOfFreeDay')}" />
							</f:facet>
							<h:outputText value="#{freeDay.outOfWork}" />
						</p:column>
						<p:column sortBy="#{loadScheduleController.sortByDate(freeDay.dateFrom)}">
				            <f:facet name="header">
				                <h:outputText value="#{translatorService.translate('outOfWork.dateFrom')}" />
				            </f:facet>
				            <h:outputText value="#{loadScheduleController.convertDate(freeDay.dateFrom)}"/>
				        </p:column>
				        <p:column sortBy="#{loadScheduleController.sortByDate(freeDay.dateTo)}">
				            <f:facet name="header">
				                <h:outputText value="#{translatorService.translate('outOfWork.dateTo')}" />
				            </f:facet>
				            <h:outputText value="#{loadScheduleController.convertDate(freeDay.dateTo)}"/>
				        </p:column>
					</p:dataTable>
				</h:panelGrid>
			</h:form>
			<p:dialog header="#{translatorService.translate('message.warning')}" widgetVar="dlg" showEffect="explode" hideEffect="explode" height="100" modal="true" >  
	    		<h:outputText value="#{translatorService.translate('loadSchedule.beforeGeneratingText')}" />  
			</p:dialog>
			<p:ajaxStatus style="width:16px;height:16px;">  
			    <f:facet name="start">  
			        <h:graphicImage library="images" name="ajax-loading.gif" />  
			    </f:facet>  
			      
			    <f:facet name="complete">  
			        <h:outputText value="" />  
			    </f:facet>  
			</p:ajaxStatus>
			
		</ui:define>
	</ui:composition>
</h:body>

</html>